package com.huike.controller.system;

import com.huike.dto.SysPageQueryDTO;
import com.huike.dto.SysUserDTO;

import com.huike.pojo.User;
import com.huike.result.PageResult;
import com.huike.result.Result;
import com.huike.service.system.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("system/user/")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    /**
     * 用户管理分页查询
     * @param queryDTO
     * @return
     */
    @GetMapping("list")
    public  PageResult list(  SysPageQueryDTO queryDTO) {
        log.info("用户列表分页:{}", queryDTO);
        return sysUserService.list(queryDTO);
    }
    /**
     * 修改账号状态
     */
    @PutMapping("changeStatus")
    public Result changeStatus(Integer status  ) {
        log.info("修改用户状态:");
        sysUserService.changeStatus(status);
        return Result.success();
    }
    /**
     * 新增账户
     */
    @GetMapping
    public Result<String> add(SysUserDTO  userDTO) {
        log.info("新增用户:{}", userDTO);
        sysUserService.add(userDTO);
        return Result.success();
    }
    /**
     * 根据id查询账户
     */
    @GetMapping("{id}")
    public Result<SysUserDTO> selectById(@PathVariable("id") Long id) {
        log.info("根据id查询用户:{}", id);
        return Result.success(sysUserService.selectById(id));
    }
    /**
     * 修改账户
     */
    @PutMapping
    public Result<String> update(SysUserDTO  userDTO) {
        log.info("修改用户:{}", userDTO);
        sysUserService.update(userDTO);
        return Result.success();
    }
    /**
     * 删除账户
     */
    @DeleteMapping("{ids}")
    public Result<String> delete(@PathVariable("ids") List<Long> ids) {
        log.info("删除用户:{}", ids);
        sysUserService.deleteUser(ids);
        return Result.success();
    }
    /**
     * 重置密码
     */
    @GetMapping("resetPwd")
    public Result<String> reset() {
        log.info("重置密码:");

        return Result.success();
    }

}
